package com.yupin.main;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import com.yupin.mail.MailUtil;

public class MailPanel extends JPanel {

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public MailPanel(){

		this.setSize(500, 400);
		this.setLayout(null);
		this.setBackground(Color.LIGHT_GRAY);

		
		init();
	}
	
	private void init(){

		JLabel userLabel = new JLabel("User: ");
		JLabel pwdLabel = new JLabel("Password: ");
		JLabel receiverLabel = new JLabel("Reveicer: ");
		final JTextField userTF = new JTextField();
		final JPasswordField pwdTF = new JPasswordField();
		final JTextField receiverTF = new JTextField();
		final JTextField subjectTF = new JTextField();
		final JTextField contentTF = new JTextField();
		JButton sendBtn = new JButton("Send");
		
		this.add(userLabel);
		this.add(pwdLabel);
		this.add(receiverLabel);
		this.add(userTF);
		this.add(pwdTF);
		this.add(receiverTF);
		this.add(contentTF);
		this.add(sendBtn);
		this.add(subjectTF);
		
		userLabel.setBounds(50, 50, 70, 20);
		userTF.setBounds(130, 50, 150, 20);
		
		pwdLabel.setBounds(50, 80, 70, 20);
		pwdTF.setBounds(130, 80, 150, 20);
		
		receiverLabel.setBounds(50, 110, 70, 20);
		receiverTF.setBounds(130, 110, 150, 20);
		
		
		
		subjectTF.setBounds(80, 190, 200, 20);
		contentTF.setBounds(80, 220, 200, 100);
		sendBtn.setBounds(300, 200, 70, 30);
	
		
		sendBtn.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent e) {
		
				String username = userTF.getText();
				System.out.println("Username: " + username);
				String password = new String(pwdTF.getPassword());
				System.out.println("Pwd: " + password);
				String receiver = receiverTF.getText();
				System.out.println("receiver: " + receiver);
				String content = contentTF.getText();
				System.out.println("content: " + content);
				String subject = subjectTF.getText();
				System.out.println("subject: " + subject);
				
				MailUtil.sendEmail(username,password,receiver,subject,content);	
			}
		});
	}
	
}
